-- The basic stuff used to damage a grid
setDefaultProjector(function(src, x, y, type, dam)
	local target = game.level.map(x, y, Map.ACTOR)
	if target then
		-- Reduce damage with resistance
		if target.resists then
			local res = (target.resists.all or 0) + (target.resists[type] or 0)
			print("[PROJECTOR] res", res, (100 - res) / 100, " on dam", dam)
			if res >= 100 then dam = 0
			else dam = dam * ((100 - res) / 100)
			end
		end

		local flash = game.flash.NEUTRAL
		if target == game.player then flash = game.flash.BAD end
		if src == game.player then flash = game.flash.GOOD end

		game.logSeen(target, flash, "%s hits %s for %s%0.2f %s damage#LAST#.", src.name:capitalize(), target.name, DamageType:get(type).text_color or "#aaaaaa#", dam, DamageType:get(type).name)
		local sx, sy = game.level.map:getTileToScreen(x, y)
		if target:takeHit(dam, src) then
			if src == game.player or target == game.player then
				game.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, -3, "Kill!", {255,0,255})
			end
		else
			if src == game.player then
				game.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, -3, tostring(-math.ceil(dam)), {0,255,0})
			elseif target == game.player then
				game.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, -3, tostring(-math.ceil(dam)), {255,0,0})
			end
		end
		return dam
	end
	return 0
end)

newDamageType{
	name = "physical", type = "PHYSICAL",
}

newDamageType{
	name = "earth", type = "EARTH", text_color = "#UMBER#",
}

newDamageType{
	name = "fire", type = "FIRE", text_color = "#RED#",
}

newDamageType{
	name = "cold", type = "COLD", text_color = "#LIGHT_BLUE#",
}

newDamageType{
	name = "lightning", type = "LIGHTNING", text_color = "#GOLD#",
}

newDamageType{
	name = "mana", type = "MANA", text_color = "#VIOLET#",
}

newDamageType{
	name = "chaos", type = "CHAOS", text_color = "#LIGHT_GREEN#",
}
